home *** CD-ROM | disk | FTP | other *** search
/ What PC? 1998 December / WPCDEC98.ISO / dxrs / Mainmn12.dxr / internet_25_Cut-n-paste high-level handlers.ls < prev    next >
Encoding:
Text File  |  1998-10-12  |  5.2 KB  |  186 lines

  1. on getExtensionApp theExt
  2.   if not stringp(theExt) then
  3.     warning("getExtensionApp(): theExt not a string")
  4.     return "Error: getExtensionApp(): theExt not a string"
  5.   end if
  6.   set dummyName to the pathName & "dummy." & theExt
  7.   if fileExists(dummyName) then
  8.     return insureShortFileName(locateExecutable(dummyName))
  9.   end if
  10.   if not objectp(factory("FileIO")) then
  11.     if not fileExists(the pathName & "FileIO.DLL") then
  12.       warning("getExtensionApp(): FileIO not available")
  13.       return "Error: getExtensionApp(): can't locate FileIO.DLL"
  14.     end if
  15.     openXLib("FileIO.DLL")
  16.   end if
  17.   if not objectp(factory("FileIO")) then
  18.     warning("getExtensionApp(): No FileIO factory.")
  19.     return "Error: getExtensionApp(): no FileIO factory"
  20.   end if
  21.   set fioObject to fileio(mnew, "write", dummyName)
  22.   if not objectp(fioObject) then
  23.     warning("getExtensionApp(): FileIO(mNew, ''write''... failed")
  24.     return "Error: getExtensionApp(): FileIO(mNew, ''write'' ... failed"
  25.   end if
  26.   fioObject(mWriteString, " ")
  27.   fioObject(mdispose)
  28.   set answer to insureShortFileName(locateExecutable(dummyName))
  29.   set fioObject to fileio(mnew, "read", dummyName)
  30.   if objectp(fioObject) then
  31.     fioObject(mDelete)
  32.   end if
  33.   return answer
  34. end
  35.  
  36. on insureShortFileName theFile
  37.   global shortname, gVoid
  38.   if not stringp(theFile) then
  39.     warning("insureShortFileName(): theFile not a string")
  40.     return gVoid
  41.   end if
  42.   if word 1 of theFile = "Error:" then
  43.     return theFile
  44.   end if
  45.   set shortname to getShortFileName(theFile)
  46.   if shortname = EMPTY then
  47.     return theFile
  48.   end if
  49.   if word 1 of shortname = "Error:" then
  50.     return theFile
  51.   end if
  52.   return shortname
  53. end
  54.  
  55. on getNamedTasks theTaskName
  56.   global gMasterAppObject
  57.   insureMasterApp()
  58.   set allTasks to getTaskIDs()
  59.   if word 1 of allTasks = "Error:" then
  60.     warning("getNamedTasks(): getTaskIDs() failed with '" & allTasks & "'")
  61.     return []
  62.   end if
  63.   set nw to the number of words in allTasks
  64.   if nw < 1 then
  65.     warning("getNamedTasks(): mGetTaskIDs returned no tasks")
  66.     return []
  67.   end if
  68.   set theTasks to []
  69.   repeat with i = 1 to nw
  70.     set thisTaskWord to word i of allTasks
  71.     set thisTaskID to integer(thisTaskWord)
  72.     if integerp(thisTaskID) then
  73.       if taskName(thisTaskID) = theTaskName then
  74.         add(theTasks, thisTaskID)
  75.       end if
  76.     end if
  77.   end repeat
  78.   return theTasks
  79. end
  80.  
  81. on cancelAnyDialogs windowID
  82.   if not integerp(windowID) then
  83.     warning("cancelAnyDialogs(): windowID not an integer")
  84.     return 0
  85.   end if
  86.   if not windowExists(windowID) then
  87.     warning("cancelAnyDialogs(): window doesn't exist")
  88.     return 0
  89.   end if
  90.   set motherTask to getWindowTask(windowID)
  91.   set taskChildren to getTaskWindowIDs(motherTask)
  92.   set nw to the number of words in taskChildren
  93.   if nw < 1 then
  94.     return 1
  95.   end if
  96.   repeat with i = 1 to nw
  97.     set thisChild to integer(word i of taskChildren)
  98.     if integerp(thisChild) then
  99.       if windowHasChildren(thisChild) then
  100.         set taskGrandchildren to getChildWindowIDs(thisChild)
  101.         set nwg to the number of words in taskGrandchildren
  102.         if nwg < 1 then
  103.           next repeat
  104.         end if
  105.         repeat with k = 1 to nwg
  106.           set thisGrandchild to integer(word k of taskGrandchildren)
  107.           if integerp(thisGrandchild) then
  108.             if not (windowName(thisGrandchild) = "Cancel") then
  109.               next repeat
  110.             end if
  111.             if not (windowType(thisGrandchild) = "Button") then
  112.               next repeat
  113.             end if
  114.             pressButton(thisGrandchild)
  115.           end if
  116.         end repeat
  117.       end if
  118.     end if
  119.   end repeat
  120.   return 1
  121. end
  122.  
  123. on pressButton windowID
  124.   if not integerp(windowID) then
  125.     warning("pressButton(): windowID not an integer")
  126.     return 0
  127.   end if
  128.   if not windowExists(windowID) then
  129.     return 1
  130.   end if
  131.   set buttonRect to getWindowOutsideRect(windowID)
  132.   set x to (integer(word 1 of buttonRect) + integer(word 3 of buttonRect)) / 2
  133.   set y to (integer(word 2 of buttonRect) + integer(word 4 of buttonRect)) / 2
  134.   set theTask to getWindowTask(windowID)
  135.   fakeMouseClick(windowID, x, y)
  136.   set giveUpTicks to the ticks + (5 * 60)
  137.   repeat while the ticks < giveUpTicks
  138.     if not windowExists(windowID) then
  139.       return 1
  140.     end if
  141.     feedTimeSlice(theTask)
  142.     feedGenericTimeSlice()
  143.   end repeat
  144.   return 0
  145. end
  146.  
  147. on menuPress windowID
  148.   if not integerp(windowID) then
  149.     warning("menuPress(): windowID not an integer")
  150.     return 
  151.   end if
  152.   if not windowExists(windowID) then
  153.     warning("menuPress(): windowID doesn't exists")
  154.     return 
  155.   end if
  156.   set theTask to getWindowTask(windowID)
  157.   showMenu(windowID)
  158.   feedTimeSlice(theTask)
  159.   feedGenericTimeSlice()
  160.   if the paramCount = 1 then
  161.     return 
  162.   end if
  163.   repeat with i = 2 to the paramCount
  164.     if not stringp(param(i)) then
  165.       warning("menuPress(): parameter " & string(i) & " not a string")
  166.       return 
  167.     end if
  168.     set nc to the number of chars in param(i)
  169.     if nc <> 1 then
  170.       warning("menuPress(): parameter " & string(i) & " not a 1-character string")
  171.       return 
  172.     end if
  173.     fakeCharacter(windowID, char 1 of param(i))
  174.     feedTimeSlice(theTask)
  175.     feedGenericTimeSlice()
  176.   end repeat
  177. end
  178.  
  179. on directorScoreWindow
  180.   return unimp()
  181. end
  182.  
  183. on unimp
  184.   warning("unimplemented")
  185. end
  186.